<? 
include "include/config.php";  
$location='date_user';

if(!isset($_SESSION['_user'])) { 
header("location: login.php");
}

if ($_SESSION['_level'] == 0) {
    header ("location: index.php");
} 
    
    
    
$nume = $_POST['nume'];
$functie = $_POST['functie'];
$adresa = $_POST['adresa'];
$telefon = $_POST['telefon'];
$mobil = $_POST['mobil'];
$fax = $_POST['fax'];
$email = $_POST['email'];
$internet = $_POST['internet'];
$motto = $_POST['motto'];        

if ($_POST['nume'] != '') {       
        
    $sql = "UPDATE users SET name='$nume', functie='$functie' , adresa='$adresa',  telefon='$telefon' , mobil ='$mobil' , fax='$fax',  email='$email' , internet='$internet' , motto='$motto' WHERE id=".$_SESSION['_id'] ;
    $result = mysql_query($sql) or die ('Probleme la update');
    $mesaj=  "Informatia s-a schimbat cu succes!";
     


    $width_t=150;$height_t=150;$width_n=250;$height_n=250;$width_m=600;$height_m=600;
    $c=0;  
    $i=0;
    if($_FILES['pictures0']['name']!=''){	                        
          
        list($width, $height, $type, $attr) = getimagesize($_FILES['pictures'.$i]['tmp_name']);
                                  
        switch($type) {
        case 1:
                $img=imagecreatefromgif($_FILES['pictures'.$i]['tmp_name'])
                or die('xxx');
                break ;
        case 2:
                $img=imagecreatefromjpeg($_FILES['pictures'.$i]['tmp_name'])
                or die('xxx');
                break ;
        case 3:
                $img=imagecreatefrompng($_FILES['pictures'.$i]['tmp_name'])
                        or die('xxx');
                break ;
        default:
                break 2;	
        } 
                      
        if($width_t/$height_t<$width/$height) {
            $_width=$width_t;
            $_height=(int)($height*$width_t/$width);
        }
        else {
            $_height=$height_t;
            $_width=(int)($width*$height_t/$height);
        }
                      
        $image=imagecreatetruecolor($_width,$_height);
        imagecopyresampled($image,$img,0,0,0,0,$_width+1,$_height+1,$width-1,$height-1);
        $imagename=$_SESSION["_id"]."_ag.jpg";                                
       
        
        //imageantialias($image, true);
        imagejpeg($image,substr(srvd, 0, -6)."imagini/thumbs/".$imagename,100);
         // normal
        if($width_n/$height_n<$width/$height) {
              $_width=$width_n;
              $_height=(int)($height*$width_n/$width);
        }
        else {
              $_height=$height_n;
              $_width=(int)($width*$height_n/$height);
        }
        $image=imagecreatetruecolor($_width,$_height);
        imagecopyresampled($image,$img,0,0,0,0,$_width+1,$_height+1,$width-1,$height-1);
        //imageantialias($image, true);
        imagejpeg($image,substr(srvd, 0, -6)."imagini/normale/".$imagename,100);
        // mare
        if($width_m/$height_m<$width/$height) {
            $_width=$width_m;
            $_height=(int)($height*$width_m/$width);
        }
        else {
                $_height=$height_m;
                $_width=(int)($width*$height_m/$height);
        }
        $image=imagecreatetruecolor($_width,$_height);
        imagecopyresampled($image,$img,0,0,0,0,$_width+1,$_height+1,$width-1,$height-1);
        //imageantialias($image, true);
        imagejpeg($image,substr(srvd, 0, -6)."imagini/mari/".$imagename,100);
        mysql_query("UPDATE users SET img='".$imagename."' WHERE id='".$_SESSION["_id"]."'");                                  
    }     
}

$user_mod_query=mysql_query("select * from users where id='" . $_SESSION['_id'] . "' ");
$data_mod= mysql_fetch_assoc($user_mod_query);    
include "include/head.php"; 

?>


<div id="container">
<? include "include/meniu.php"; ?>

<div id="submenu"><div><div>
    <ul>
        <li id="off2"><a href="date_user.php">Date Agent</a></li>
    </ul>
</div></div></div>

<div class="clear"></div>
<div id="content"><div id="mid">
<div>

           <h2>Introduceti date: </h2>

            <form action = "date_user.php" method = "post" enctype = "multipart/form-data"  >           
                 <label>Nume</label>
                <input name = "nume"  type = "text" class = "tf b" value='<?=stripslashes($data_mod['name'])?>'/> <br class = "clear"/>                
                 <label>Functie</label>
                <input name = "functie"  type = "text" class = "tf b" value='<?=stripslashes($data_mod['functie'])?>'/> <br class = "clear"/>
                 <label>Adresa de lucru</label>
                <input name = "adresa"  type = "text" class = "tf bbb" value='<?=stripslashes($data_mod['adresa'])?>'/> <br class = "clear"/>
                
                <label>Telefon Birou</label>
                <input name = "telefon"  type = "text" class = "tf bbb" value='<?=stripslashes($data_mod['telefon'])?>'/> <br class = "clear"/>
                <label>Telefon Mobil</label>
                <input name = "mobil"  type = "text" class = "tf bbb" value='<?=stripslashes($data_mod['mobil'])?>'/> <br class = "clear"/>
                <label>Fax</label>
                <input name = "fax"  type = "text" class = "tf bbb" value='<?=stripslashes($data_mod['fax'])?>'/> <br class = "clear"/>
                <label>Email</label>
                <input name = "email"  type = "text" class = "tf bbb" value='<?=stripslashes($data_mod['email'])?>'/> <br class = "clear"/>
                <label>Internet</label>
                <input name = "internet"  type = "text" class = "tf bbb" value='<?=stripslashes($data_mod['internet'])?>'/> <br class = "clear"/>
                <label>Motto</label>
                <textarea name = "motto"  type = "text" class = "tf bbbbb"  rows=15><?=stripslashes($data_mod['motto'])?></textarea> <br class = "clear"/>  
               
               <label>Adauga imagine</label>
               <input name="pictures0" type="file" class="tf bb"  />  <br class = "clear"/> 
                
                <? if($data_mod["img"]!="") { 
                   echo "<img src='../imagini/thumbs/".$data_mod['img']."'  class='pict' /> "; 
                } ?>
                
                <br class = "clear"/>
                <label>&nbsp;</label>

                <input type = "submit" name = "modifica" value = "Modifica" class = "ok"/>
                <br class = "clear"/>
            </form>
            
            <? if ($mesaj!='') { ?>
            <br class="clear" />
            <div class="cell__ bbbbb ac"><strong><?=$mesaj?></strong></div>
            <? } ?>   

</div>
</div>
</div>
<? include "include/footer.php";  ?> 